{% extends "asgn/base.html" %}
{% load friendly_time %}
{% block asgn_page_title%}作业批改{% endblock %}
{% block asgn_page_body %}
<form action="{% url 'asgn_mgr_save_asgn_checkup_fast' asgn.id %}" method="post" id="checkup_list_form">
    <div class="problemlist_item">
        <div class="header" id="fast_checkup_bar">
            统一作业批改&nbsp;<small style="color: #999; font-size: 14px">点击展开</small>
        </div>
        <div class="body" id="fast_checkup" style="display: none">
            <div class="content">
                <span>请先在下方列表中选择需要批改的学生。执行批改后，原先的评分信息以及评语信息都将被覆盖</span><br /><br />
                <div class="input-group">
                    <div class="input-group-addon">统一评分</div>
                    <input class="form-control" id="teacher_score" name="teacher_score" value="{{ asgn.full_score }}" disabled/>
                    <div class="input-group-addon"><input id="btn_use_judge_score" type="checkbox" value="1" name="use_judge_score" checked> 使用判题机分数</div>
                </div><br />
                <h4>评语</h4>
                <textarea class="form-control" id="teacher_remark" name="teacher_remark"  rows="10"></textarea>
                <br>
                <button type="submit" id="fast_checkup_btn" class="btn btn-primary">执行批改</button>
            </div>
        </div>
    </div>
    <h3>作业列表 <small><a id="btn_refresh_judge_score" href="javascript:void(0)">判题分数重算</a></small></h3>
    <hr>
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th><input type="checkbox" id="select-all" checked></th>
                <th>学号</th>
                <th>姓名</th>
                <th>最后提交时间</th>
                <th>解决数/AC数/提交数</th>
                <th>判题机给分</th>
                <th>老师给分</th>
                <th>评测记录</th>
                <th>点击手动批改</th>
            </tr>
        </thead>
        <tbody>
        {% for report in report_list %}
            <tr>
                <td><input type="checkbox" name="sids" class="bm-checkbox" value="{{ report.student.id }}" checked/></td>
                <td>{{ report.student.id }}</td>
                <td><a href="{% url 'account_space' report.student.id %}" target="_blank">{{ report.student.realname }}</a></td>
                {% if report.created == False %}
                <td colspan="5" align="center">未提交</td>
                {% else %}
                <td>{% if report.modify_time > 0  %}{{ report.modify_time | friendly_time }}{% else %}无{% endif %}</td>
                <td><span class="text-primary"><strong>{{ report.solved_counter }}</strong></span> / <span class="text-success">{{ report.ac_counter }}</span> / {{ report.submission_counter }} </td>
                <td>{{ report.judge_score | default:0 }}</td>
                <td>{% if report.teacher_check %}{{ report.finally_score }}{% else %} 未批改 {% endif %}</td>
                <td>
                    <a href="{% url 'asgn_status_list' asgn.id %}?author_id={{ report.student.id }}" title="点击查看评测记录" class="label label-info" target="_blank">评测记录</a>

                </td>
                <td>
                {% if report.teacher_check %}
                    <a href="{% url 'asgn_show_report' asgn.id report.student.id %}" class="label label-success" target="_blank">已批阅</a>
                {% else %}
                    <a href="{% url 'asgn_show_report' asgn.id report.student.id %}" class="label label-warning" target="_blank">待批阅</a>
                {% endif %}
                </td>
                {% endif %}
            </tr>
        </tbody>
        {% empty %}
            <tr>
                <td colspan="7" align="center">还没有人交过作业</td>
            </tr>
        {% endfor %}
    </table>
</form>
{% endblock %}
{% block asgn_page_script %}
    <script type="text/javascript" src="/static/ckeditor/ckeditor.js"></script>
    <script type="text/javascript">
    $(function () {

        $("#fast_checkup_bar").click(function(){
            $("#fast_checkup").slideToggle();
        });
        $("#btn_use_judge_score").change(function () {
           $("#teacher_score").prop("disabled", $(this).prop("checked"));
        });
        var running_refresh_judge_score = false;
        $("#btn_refresh_judge_score").click(function () {
            if (running_refresh_judge_score) return;
            $.ConfirmBox({
                color: 'primary',
                title: '提示',
                body: '重算需要一定的时间，请耐心等待',
                callback:function (flag) {
                    if(flag){
                        running_refresh_judge_score = true;
                        $("#btn_refresh_judge_score").text("重算操作执行中，请不要刷新界面！");
                        $.GRestP({
                            responseType: 'json',
                            callback: function (flag, entity) {
                                running_refresh_judge_score = false;
                                $("#btn_refresh_judge_score").text("判题分数重算");
                                if(flag){
                                    $.AlertBox({
                                        body: "重算操作完成",
                                        color: "success",
                                        title: "操作成功",
                                        callback: function () {
                                            $.ModalBox({}).hide();
                                            window.location.reload();
                                        }
                                    }).show();
                                }else{
                                    $.AlertBox({body: entity.msg, color: "danger", title: "操作失败"}).show();
                                }
                            }
                        }).call('{% url 'asgn_mgr_refresh_judge_score' asgn.id %}')
                    }
                }
            }).show();
        });


        CKEDITOR.replace( 'teacher_remark', { height:'15em' } );
        var $bm_form = $("#checkup_list_form");
        $bm_form.find("#select-all").change(function () {
            $bm_form.find(".bm-checkbox").prop("checked", $(this).prop("checked"));
        });
        $bm_form.submit(function () {
            for (var ins in CKEDITOR.instances) CKEDITOR.instances[ins].updateElement();
            $.GRestP({
                responseType: 'json',
                callback: function (flag, entity) {
                    if (flag) {
                        $.AlertBox({
                            body: "作业批改完毕",
                            color: "success",
                            title: "操作成功",
                            callback: function () {
                                $.ModalBox({}).hide();
                                window.location.reload();
                            }
                        }).show();
                    } else {
                        $.AlertBox({body: entity.msg, color: "danger", title: "操作失败"}).show();
                    }
                }
            }).submit_form(this);
            return false;
        });
    });
    </script>
{% endblock %}